package siwi.map.android;

import java.util.regex.Pattern;

import siwi.map.android.R;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.wmw.Utility.Common;

import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Process;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class GPSLocateService extends Service {
	private EditText mTv = null;
	private boolean  mIsStart;
	private static int count = 1;
	private Vibrator mVibrator01 =null;
	private LocationClient mLocClient;

	public static String TAG = "LocTestDemo";

	@Override
	public void onCreate() {
		super.onCreate();  
		mIsStart = false;

		mLocClient = ((ExApplication)getApplication()).mLocationClient;
		((ExApplication)getApplication()).mTv = mTv;
		mVibrator01 =(Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);
		((ExApplication)getApplication()).mVibrator01 = mVibrator01;

		setLocationOption();
		mLocClient.start();
		mIsStart = true;
		
		if (mLocClient != null && mLocClient.isStarted()){
			setLocationOption();
			mLocClient.requestLocation();	
		}
		else 
			Log.d(Common.MARS, "locClient is null or not started");
	}
	
	@Override
	public void onDestroy() {
		mLocClient.stop();
		((ExApplication)getApplication()).mTv = null;
		super.onDestroy();
	}

	//设置相关参数
	private void setLocationOption(){
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true); //打开GPS
		option.setCoorType("bd09ll");		//设置坐标类型
		option.setServiceName("com.baidu.location.service_v2.9");
		option.setPoiExtraInfo(true);
		option.setAddrType("all");

		option.setScanSpan(3000); //设置定位模式，小于1秒则一次定位;大于等于1秒则定时定位
		
		option.setPriority(LocationClientOption.GpsFirst);        //不设置，默认是gps优先
		
		option.setPoiNumber(10);
		option.disableCache(true);		
		mLocClient.setLocOption(option);
	}

	protected boolean isNumeric(String str) {   
		Pattern pattern = Pattern.compile("[0-9]*");   
		return pattern.matcher(str).matches();   
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}  


}